home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5330 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.os.msdos.programmer,comp.lang.c
  4. Subject: Re: open vs fopen?
  5. Date: 9 Feb 1996 21:32:16 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Distribution: na
  8. Message-ID: <4fhal0INN7vm@keats.ugrad.cs.ubc.ca>
  9. References: <uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f8qf1$h3b@ssbunews.ih.att.com>
  10. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  11.  
  12. In article <4f8qf1$h3b@ssbunews.ih.att.com>,
  13. Harold E. Bamford <bamford@marconi.ih.att.com> wrote:
  14. >In article <uEYFxc9nX8WX083yn@mbnet.mb.ca>,
  15. >Nathan T. Wild <natewild@mbnet.mb.ca> wrote:
  16. >
  17. >>In C, why would one use open and DOS int handles rather than fopen and
  18. >>stdio file handles?
  19. >>
  20. >>Is there some speed advantage or differnet functionality?
  21. >
  22. >open() is for raw I/O.  You use read(), write(), lseek(), ltell()
  23. >
  24. >fopen() is for buffered I/O.  You can use fread(), fscanf(), fgets(),
  25. >getchar(), putchar, fprint(), fwrite(), fseek(), ftell(), etc.
  26.  
  27. False. Both are buffered. The latter does an extra copy.
  28.  
  29. The justification for the extra buffering in the latter is that you can pump
  30. data in smaller chunks _without_ causing needless context switches to the
  31. kernel.
  32.  
  33. Calling fread() a byte at a time is much more efficient than calling read() a
  34. byte at a time, because each call to read() causes a call to the kernel.
  35.  
  36. However, calling read() several kilobytes at a time is more efficient than
  37. fread(), because it dispenses with an extra level of overhead.
  38.  
  39. >For certain applications, you can get away without buffering.  But
  40. >often it is easier to do the programming if you don't have to worry
  41. >about unneeded system calls and buffering gives you that.
  42.        ^^^^^^^^^^^^^^^^^^^^^
  43.  
  44. Ah, now you are hitting much closer to the target!
  45. -- 
  46.  
  47.